package lgq.xuan.httprequest.phone.manager;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;

import lgq.xuan.httprequest.phone.manager.base.BasePermissionManager;

public class MessageSendPermissionManager extends BasePermissionManager {

    private final int MESSAGE_SEND_PERMISSION_CODE = 101010010;

    public MessageSendPermissionManager(@NonNull Activity activity) {
        super(activity);
    }

    @Override
    public boolean checkAllNeedPermission() {
        return checkSendSms() && checkReadPhoneState();
    }

    public boolean checkReadPhoneState() {
        int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE);
        return permission == PackageManager.PERMISSION_GRANTED;
    }

    public boolean checkSendSms() {
        int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.SEND_SMS);
        return permission == PackageManager.PERMISSION_GRANTED;
    }

    @Override
    public void requestAllNeedPermission() {
        String[] permissions = {
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.SEND_SMS,
        };

        ActivityCompat.requestPermissions(
                activity,
                permissions,
                MESSAGE_SEND_PERMISSION_CODE
        );
    }
}
